package edu.ccut.saturn.component.impl.sql;

public class ParameterToken {

	public static final String TOKEN_START = "${";

	public static final String TOKEN_END = "}";

	private int startIndex;

	private int endIndex;

	private String paramName;

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public String getParamName() {
		return paramName;
	}

	public void setParamName(String paramName) {
		this.paramName = paramName;
	}

	public ParameterToken(int startIndex, int endIndex, String paramName) {
		this.startIndex = startIndex;
		this.endIndex = endIndex;
		this.paramName = paramName;
	}

	public void replace(StringBuffer text, String valueStr) {

		if (endIndex == text.length() - 1) {
			text.append(" ");
		}
		text.replace(text.indexOf(TOKEN_START), text.indexOf(TOKEN_END) + 1,
				valueStr);
	}
}
